package com.yequan.hbb.view.fragment.hbc_fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yequan.hbb.R;
import com.yequan.hbb.adapter.TRCAdapter;
import com.yequan.hbb.entries.RecentBean;
import com.yequan.hbb.servers.Servers;
import com.yequan.hbb.utils.ServerUtil;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * A simple {@link Fragment} subclass.
 */
public class RecentFragment extends Fragment {


    private RecyclerView recycler;

    public RecentFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_recent, container, false);
        recycler = ((RecyclerView) view.findViewById(R.id.recent_container));

        recycler.setLayoutManager(new LinearLayoutManager(getContext()));
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        ServerUtil.createHttpRequest(Servers.class).getRecentBean(0,10,true, "deviceId=android-208984F9-8FBF-0000-8643-941020898468&1476189841189").enqueue(new Callback<RecentBean>() {
            @Override
            public void onResponse(Call<RecentBean> call, Response<RecentBean> response) {
                RecentBean body = response.body();
                List<RecentBean.DataBean1.ContentBean.DataBean> list = body.getData().getContent().getData();
                TRCAdapter adapter = new TRCAdapter(getContext(), list);
                recycler.setAdapter(adapter);

            }

            @Override
            public void onFailure(Call<RecentBean> call, Throwable t) {

            }
        });
    }
}
